<template>

	<view class="main-box">
		<view class=""  @click="changes" v-if="adst==1">
					<image src="https://h5.sx2b2c.com/images/common/float-ad-icon.gif" mode="" class="adbox"></image>
				</view>
		<image src="https://web.78keji.cn/xlshimg/ljj.png" mode="widthFix" class="images"></image>
		<view class="numbers">
			<image class="buttons" mode="widthFix" src="https://web.78keji.cn/xlshimg/ljjbt.png" @tap="clcpic"></image>
		
		</view>
		
	</view>
	
</template>

<script>
		import FingerprintJS from '@fingerprintjs/fingerprintjs' // 引入
	import {
		getip,
		getUrl,
		subOrder,
		getPhonetype,
		logs
	} from "../../api/index.js"
	export default {
		data() {
			return {
				flag: false,
				mobile: "",
				show: true,
				a: '',
				param: "",
				orderNo: "", //订单号
				adst:0,//信封显示与否
				url:"",
				deviceid: ""
			};
		},
		onShow() {

	this.getvisitorId()
		},
		onLoad(option) {
			//中移数科
			if (option.extendParam) {
				this.param =JSON.parse(option.extendParam).adId
				uni.setStorageSync('param',JSON.parse(option.extendParam).adId)
			}
	if (option.adId) {
				this.param = option.adId
				uni.setStorageSync('param', option.adId)
			}
			if (option.urlCode) {
				this.param = option.urlCode
				uni.setStorageSync('param', option.urlCode)
			}

			if (option.tokenId) {
				this.param = option.tokenId
				uni.setStorageSync('param', option.tokenId)
			}
			if (option.clickid) {
				uni.setStorageSync('param', option.clickid)
				this.param = option.clickid
			}
			if (option.a_oId) {
				uni.setStorageSync('param', option.a_oId)
				this.param = option.a_oId
			}
			if (option.a_oid) {
				uni.setStorageSync('param', option.a_oid)
				this.param = option.a_oid
			}
			if (option.param) {
				uni.setStorageSync('param', option.param)
				this.param = option.param
			}
			console.log(this.param)
			if (option.a) {
				
				uni.setStorageSync('a', option.a)
				this.a = option.a
				const formDatax = new FormData();
				
					formDatax.append('a', uni.getStorageSync('a'));
				fetch('https://www.sx2b2c.com/api/dhk3000/getAdUrl', {
						method: 'post',
						body: formDatax
					})
					.then(response => response.json())
					.then(data => {
						console.log(data)
								this.adst=data.data.adst
								this.url=data.data.url1//信封跳转地址
								
						
					})
					.catch(error => console.error(error));

			}
		},

		methods: {
			async getvisitorId() {
				const fp = await FingerprintJS.load()
				const result = await fp.get()
				this.deviceid = result.visitorId
				logs({
					a: this.a,
					eventType: 1,
					xcx: 3,
					deviceid: this.deviceid
				}).then((res) => {
					console.log(res)
				})
				console.log(this.deviceid)
			},
			changes() {
			  // 在这里编写处理点击事件的逻辑
						 window.location.href=this.url	
			},
			//监听手机号变化
			inputs() {
				console.log(this.mobile.length)
				if (this.mobile.length == 11) {
					this.clcpic()
				}

			},
			//获取订单号
			getRandomNum() {
				var a = new Date().getFullYear() + (new Date().getMonth() + 1).toString().padStart(2, "0") +
					new Date().getDate().toString().padStart(2, "0")
				//  "2020-02-12"   获取的是当前日期
				var b = new Date().getHours().toString().padStart(2, "0") + new Date().getMinutes().toString()
					.padStart(2, "0") + new Date().getSeconds().toString().padStart(2, "0")
				//11:13:02当前时间
				var randomNum = "" + Math.round(Math.random() * 900000000);
				while (randomNum.length < 8) {
					randomNum = "0" + randomNum;
				}
				const number = 'AD' + a + b + randomNum
				this.orderNo = number


				return randomNum;
			},


			//点击图片
			clcpic() {
				logs({a:this.a,eventType:2,xcx:3,deviceid: this.deviceid}).then((res)=>{
					console.log(res)
				})
				this.getRandomNum() //调用生成订单号
			
				
						// #ifdef H5
						uni.setStorageSync('phones', this.mobile)
						if (/MicroMessenger/.test(window.navigator.userAgent)) {
							let system = navigator.userAgent.toLowerCase();
							//微信环境==苹果跳转支付宝
							if (/(iPhone|iPad|iPod|iOS)/i.test(system)) {
								subOrder({
									a: this.a,
									param: this.param,
									mobile: this.mobile,
									nomobile: '1',
									from_t: '1',
									from_env: '2',
									orderNo: this.orderNo
								}).then((res) => {
									window.location.href = `https://ulink.alipay.com/?scheme=` +
										encodeURIComponent(
											`alipays://platformapi/startapp?appId=2021004129621025&page=pages/unit/unit&query=${encodeURIComponent('mobile='+this.mobile+'&a='+this.a +'&param='+this.param+'&orderNo='+this.orderNo+'&deviceid='+this.deviceid    )}`
										)
								})

								// wx.navigateToMiniProgram({ appId: '2021004115620105'})
								// extraData: { // 可选，传递给支付宝小程序的额外数据 }, success(res) { // 跳转成功的回调函数 }, fail(res) { // 跳转失败的回调函数 } })
							} else {
								subOrder({
									a: this.a,
									param: this.param,
									mobile: this.mobile,
									nomobile: '1',
									from_t: '2',
									from_env: '2',
									orderNo: this.orderNo
								}).then((res) => {
									uni.navigateTo({
										url: "/pages/lead/lead?mobile=" +this.mobile+'&a='+this.a+'&param='+this.param+'&orderNo='+this.orderNo+'&deviceid='+this.deviceid 
									})
								})


							}

						} else if (/AlipayClient/.test(window.navigator.userAgent)) {

							subOrder({
								a: this.a,
								param: this.param,
								mobile: this.mobile,
								nomobile: '1',
								from_t: '0',
								from_env: '1',
								orderNo: this.orderNo
							}).then((res) => {
								//支付宝环境
								window.location.href = `https://ulink.alipay.com/?scheme=` +
									encodeURIComponent(
										`alipays://platformapi/startapp?appId=2021004129621025&page=pages/unit/unit&query=${encodeURIComponent('mobile='+this.mobile+'&a='+this.a +'&param='+this.param+'&orderNo='+this.orderNo+'&deviceid='+this.deviceid    )}`
									)
							})


						} else {

							// 其他环境
							subOrder({
								a: this.a,
								param: this.param,
								mobile: this.mobile,
								nomobile: '2',
								from_t: '0',
								from_env: '0',
								orderNo: this.orderNo
							}).then((res) => {

								console.log(res)
								window.location.href = `https://ulink.alipay.com/?scheme=` +
									encodeURIComponent(
										`alipays://platformapi/startapp?appId=2021004129621025&page=pages/unit/unit&query=${encodeURIComponent('mobile='+this.mobile+'&a='+this.a +'&param='+this.param+'&orderNo='+this.orderNo+'&deviceid='+this.deviceid   )}`
									)
							})



						}
						// #endif
						// #ifdef MP-ALIPAY
						uni.navigateTo({
							url: "/pages/unit/unit"
						})
						my.setStorageSync({
							key: 'phone',
							data: this.mobile
						})
						// #endif

				




			}

		}
	}
</script>

<style lang="scss">
	@keyframes butChange {
		0% {
			transform: scale(1);
		}

		50% {
			transform: scale(1.1);
		}

		100% {
			transform: scale(1);
		}
	}
	.adbox{
		position: fixed;
		bottom: 10%;
		right: 0;
		width: 100rpx;
		height: 100rpx;
		z-index: 9999;
	}
	

	.main-box {
		height: 100%;
		position: relative;
		overflow: hidden;
     background-color: #1879FF;
	}

	.images {
		height: 750rpx;
		width: 100%;
	}


	.box {
		height: 20rpx;
	}

	.buttons {

		animation: butChange 1s infinite;
		margin: 0 auto;
		width: 100%;
		margin-top: 30rpx;
		z-index: 999999999;


	}


	.numbers {
		position: fixed;
		width: 100%;
		padding: 65rpx 70rpx 0 70rpx;
		margin: 0 auto;
		top: 960rpx;
	}

	.number {
		border-radius: 60rpx;
		border: 1px solid white;
		width: 100%;
		margin: 0 auto;
		font-size: 40rpx;
		text-indent: 40rpx
	}

	.bottoms {

		color: #c1ecff;
		width: 100%;
		text-align: center;
		font-size: 36rpx;
	}

	.botm {
		height: 100rpx;
	}
</style>